package com.xxq.semester.controller.exam;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.xxq.semester.entity.question.Questions;
import com.xxq.semester.service.question.IQuestionsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xxq.semester.entity.utils.ResponseEntity;
import java.util.List;
import com.xxq.semester.service.exam.IExamQuestionsService;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author saki
 * @since 2025-07-13
 */
@RestController
@RequestMapping("/api/exam-questions")
@Tag(name="考题管理", description = "选择题目")
public class ExamQuestionsController {
    @Autowired
    private IExamQuestionsService examQuestionsService;

    @Autowired
    private IQuestionsService questionsService;

    @GetMapping("")
    @Operation(summary = "获取所有题目列表", description = "获取所有题目列表")
    public ResponseEntity<List<Questions>> getQuestionsList(

    ) {
        List<Questions> list = questionsService.selectAllQuestions();
        return ResponseEntity.success(list);
    }

    @PostMapping("/select-questions")
    @Operation(summary = "选择题目并关联到考试", description = "选择题目并关联到考试")
    public ResponseEntity<String> selectQuestions(
            @RequestBody @Parameter(description = "选择题目请求体，包括考试ID和题目ID列表") ExamQuestionsController.SelectQuestionsRequest request) {
        examQuestionsService.saveSelectedQuestions(request.getExamId(), request.getQuestionIds());
        return ResponseEntity.success("题目选择成功");
    }

    public static class SelectQuestionsRequest {
        @JsonProperty("examId")
        private Long examId;
        @JsonProperty("questionIds")
        private List<Long> questionIds;
        // getter和setter
        public SelectQuestionsRequest() {}
        public Long getExamId() { return examId; }
        public void setExamId(Long examId) { this.examId = examId; }
        public List<Long> getQuestionIds() { return questionIds; }
        public void setQuestionIds(List<Long> questionIds) { this.questionIds = questionIds; }
    }
}
